#coding=UTF-8
from django.http import HttpResponse
# from django.shortcuts import render_to_response
from django.shortcuts import render
import json
from . import decodeModel
import chardet
import multiprocessing
from multiprocessing import Manager



# 接收POST请求数据
def askinfo(request):
    import os
    os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
    resultjson = ""
    print("hehe")
    if (request.method == 'POST'):
        print("haha")
        mesinfo = request.POST.get('query')
        print(chardet.detect(mesinfo.encode('utf-8')))
        # mesinfo=mesinfo.encode('UTF-8')
        print(mesinfo)
        # mesinfodict = json.loads(json.dumps(mesinfo))
        # print(mesinfodict)
        # mesinfo = mesinfodict["query"]
        # print(mesinfo)
        anwer = decodeModel.query_answer(mesinfo)
        resultjson = {"anwer": anwer}
        print(resultjson)
    return HttpResponse(json.dumps(resultjson))